let num1 = "12334567890";
let num2 = "12334567890.123456";
const result1 = num1.replace(/(\d)(?=(\d{3})+$)/g, "$1,");
console.log(result1);
const result2 = num2.replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
console.log(result2);

const format = (num) => {
  const numStr = num.toString();
  const reg =
    numStr.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(\d{3})+$)/g;
  return numStr.replace(reg, "$1,");
};

console.log(format(num1));
console.log(format(num2));
